
package com.yesep.learn.mqtt.server.broker.handler.protocol;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.yesep.learn.mqtt.protocol.IPingReq;
import com.yesep.learn.mqtt.server.common.Constants;
import com.yesep.learn.mqtt.util.ChannelUtil;

import io.netty.channel.Channel;
import io.netty.handler.codec.mqtt.MqttFixedHeader;
import io.netty.handler.codec.mqtt.MqttMessage;
import io.netty.handler.codec.mqtt.MqttMessageFactory;
import io.netty.handler.codec.mqtt.MqttMessageType;
import io.netty.handler.codec.mqtt.MqttQoS;
import io.netty.util.AttributeKey;

/**
   * 消息编号：12
 * @Description: PINGREQ连接处理，ping请求
 */
@Service
public class PingReq implements IPingReq {

	private static final Logger LOGGER = LoggerFactory.getLogger(PingReq.class);

	public void process(Channel channel, MqttMessage msg) {
		MqttMessage pingRespMessage = MqttMessageFactory.newMessage(new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0), null, null);
		LOGGER.debug("PINGREQ - clientId: {}", ChannelUtil.getClientId(channel));
		channel.writeAndFlush(pingRespMessage);
	}

}
